<?php
	namespace core;
	use stdClass;
    final class Util {
        static public function obj2Arr(stdClass $Class){
			$Class = (array)$Class;
            foreach($Class as $key => $value){
                if(is_object($value)&&get_class($value)==='stdClass'){
                    $Class[$key] = self::object_to_array($value);
                }
            }
            return $Class;
        }
        
        static public function arr2Obj(array $array){
            foreach($array as $key => $value){
                if(is_array($value)){
                    $array[$key] = self::array_to_object($value);
                }
            }
            return (object)$array;
        }
		
		static function time($str='Y-m-d H:i:s'){
			return date($str,time());
		}
		
		//复制不空的属性到对象中
		static function copyProperties($instance,$paramsArr,$excepts = array()){
			foreach($paramsArr as $key=>$val){
				if(!empty($val)){
					//排除的字段数组不null，且key在排除字段中，则不复制
					if(!empty($excepts)&&in_array($key,$excepts)) continue;
					$instance[$key] = $val;
				}
			}
		}
		
		//第一个是原串,第二个是 部份串
		static function startWith($str, $needle) {
			return strpos($str, $needle) === 0;
		}

		//第一个是原串,第二个是 部份串
		static function endWith($haystack, $needle) {  
			  $length = strlen($needle);  
			  if($length == 0)
			  {    
				  return true;  
			  }  
			  return (substr($haystack, -$length) === $needle);
		 }
    }
